package environment;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JFrame;

import agents.Aircraft;
import agents.Obstacle;
import agents.UserAircraft;

public class Sky extends JFrame {
	private Cell[][] cell = new Cell[Paramaters.NUMBER_ROWS][Paramaters.NUMBER_COLUMNS];

	public Sky() {
		for (int v = 0; v < Paramaters.NUMBER_ROWS; v++)
			for (int h = 0; h < Paramaters.NUMBER_COLUMNS; h++)
				add(cell[v][h] = new Cell(v, h, Color.GRAY));

		setSize(Paramaters.ENVIRONEMENT_WIDTH, Paramaters.ENVIRONEMENT_HIGHT);
		GridLayout GameBoard = new GridLayout(Paramaters.NUMBER_ROWS,
				Paramaters.NUMBER_COLUMNS, 1, 1);
		setLayout(GameBoard);
		setPreferredSize(new Dimension(Paramaters.ENVIRONEMENT_WIDTH,
				Paramaters.ENVIRONEMENT_HIGHT));
		
		setVisible(true);
	}

	public void setAircraft(Aircraft aircraft) {
		Cell aircraftHead = aircraft.getHead();
		Cell aircraftTail = aircraft.getTail();
		Cell aircraftLeft = aircraft.getLeft();
		Cell aircraftRight = aircraft.getRight();

		remove(cell[aircraftHead.getRow()][aircraftHead.getColumn()]);
		add(aircraftHead, (aircraftHead.getRow() - 1)
				* Paramaters.NUMBER_ROWS + aircraftHead.getColumn() - 1);

		remove(cell[aircraftRight.getRow()][aircraftRight.getColumn()]);
		add(aircraftRight, (aircraftRight.getRow() - 1)
				* Paramaters.NUMBER_ROWS + aircraftRight.getColumn() - 1);

		remove(cell[aircraftTail.getRow()][aircraftTail.getColumn()]);
		add(aircraftTail, (aircraftTail.getRow() - 1)
				* Paramaters.NUMBER_ROWS + aircraftTail.getColumn() - 1);

		remove(cell[aircraftLeft.getRow()][aircraftLeft.getColumn()]);
		add(aircraftLeft, (aircraftLeft.getRow() - 1)
				* Paramaters.NUMBER_ROWS + aircraftLeft.getColumn() - 1);
	}

	public void setObstacle(Obstacle obstacle) {

	}
}
